package org.cwgl.actions;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.cwgl.exception.MyException;
import org.cwgl.interfaces.SelectService;
import org.cwgl.model.Climas;
import org.cwgl.model.Standbook;
import org.cwgl.model.Usercase;
import org.cwgl.support.Page;
import org.cwgl.util.Json;
import org.cwgl.vo.ClimasVo;
import org.cwgl.vo.Result;
import org.cwgl.vo.StandbookVo;
import org.cwgl.vo.UsercaseVo;

public class SelectAction {

	// 查询业务类
	public SelectService service;
	public Date startTime;
	public Date endTime;
	public ClimasVo climasvo = new ClimasVo();
	public StandbookVo standbookvo = new StandbookVo();
	public UsercaseVo usercasevo = new UsercaseVo();

	public UsercaseVo getUsercasevo() {
		return usercasevo;
	}

	public void setUsercasevo(UsercaseVo usercasevo) {
		this.usercasevo = usercasevo;
	}

	public ClimasVo getClimasvo() {
		return climasvo;
	}

	public void setClimasvo(ClimasVo climasvo) {
		this.climasvo = climasvo;
	}

	public StandbookVo getStandbookvo() {
		return standbookvo;
	}

	public void setStandbookvo(StandbookVo standbookvo) {
		this.standbookvo = standbookvo;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public SelectService getService() {
		return service;
	}

	public void setService(SelectService service) {
		this.service = service;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public String findUsercaseMaoriByTime() {
		HttpServletResponse response = ServletActionContext.getResponse();
		Map map=new HashMap(0);
		Result result=new Result();
		PrintWriter out = null;
		
		result.setSuccess(false);
		try 
		{

			out = response.getWriter();
			Double money = service.findUsercaseMaoriByTime(startTime,endTime);
			result.setSuccess(true);
			map.put("moeny", money);
		} catch (MyException e) 
		{
			result.setException(e.getMessage());
		} catch (Exception e) 
		{
			result.setException(e.getMessage());
		}finally
		{
			map.put("result", result);
			out.print(Json.JSON_List(map));
			out.flush();
		}
		return (null);
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	public String findUsercaseById()
	{
		Usercase usercase=null;
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out=null;
		Result result=new Result();
		Map map=new HashMap(0);
		result.setSuccess(false);
		try 
		{
			out = response.getWriter();
			usercase=service.findUsercaseById(usercasevo.getUcid());
			result.setSuccess(true);
			result.setException("");
			result.setMsg("");
			map.put("data", usercase);
		} catch (IOException e) 
		{
			result.setException(e.getMessage());
		} catch (MyException e) 
		{
			result.setMsg(e.getMessage());
		}finally
		{
			map.put("result", result);
			out.print(Json.JSON_List(map));
			out.flush();
		}
		return null;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public String findClimasById()
	{
		Climas usercase=null;
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out=null;
		Result result=new Result();
		Map map=new HashMap(0);
		result.setSuccess(false);
		try 
		{
			out = response.getWriter();
			usercase=service.findClimasById(climasvo.getCid());
			result.setSuccess(true);
			result.setException("");
			result.setMsg("");
			map.put("data", usercase);
		} catch (IOException e) 
		{
			result.setException(e.getMessage());
		} catch (MyException e) 
		{
			result.setMsg(e.getMessage());
		}finally
		{
			map.put("result", result);
			out.print(Json.JSON_List(map));
			out.flush();
		}
		return null;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public String findStandbookById()
	{
		Standbook usercase=null;
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out=null;
		Result result=new Result();
		Map map=new HashMap(0);
		result.setSuccess(false);
		try 
		{
			out = response.getWriter();
			usercase=service.findStandbookById(standbookvo.getGid());
			result.setSuccess(true);
			result.setException("");
			result.setMsg("");
			map.put("data", usercase);
		} catch (IOException e) 
		{
			result.setException(e.getMessage());
		} catch (MyException e) 
		{
			result.setMsg(e.getMessage());
		}finally
		{
			map.put("result", result);
			out.print(Json.JSON_List(map));
			out.flush();
		}
		return null;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public String findStandbookByUsercaseId()
	{
		Page usercase=null;
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out=null;
		Result result=new Result();
		Map map=new HashMap(0);
		result.setSuccess(false);
		try 
		{
			out = response.getWriter();
			usercase=service.findStandbookByUsercaseId(usercasevo.getUcid(),usercasevo.getStart(),usercasevo.getLimit());
			result.setSuccess(true);
			result.setException("");
			result.setMsg("");
			map.put("data", usercase);
		} catch (IOException e) 
		{
			result.setException(e.getMessage());
		} catch (MyException e) 
		{
			result.setMsg(e.getMessage());
		}finally
		{
			map.put("result", result);
			out.print(Json.JSON_List(map));
			out.flush();
		}
		return null;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public String findClaimsByTime()
	{
		Page usercase=null;
		HttpServletResponse response = ServletActionContext.getResponse();
		PrintWriter out=null;
		Result result=new Result();
		Map map=new HashMap(0);
		result.setSuccess(false);
		try 
		{
			out = response.getWriter();
			usercase=service.findClaimsByTime(this.getStartTime(),this.getEndTime(),usercasevo.getStart(),usercasevo.getLimit());
			result.setSuccess(true);
			result.setException("");
			result.setMsg("");
			map.put("data", usercase);
		} catch (IOException e) 
		{
			result.setException(e.getMessage());
		} catch (MyException e) 
		{
			result.setMsg(e.getMessage());
		}finally
		{
			map.put("result", result);
			out.print(Json.JSON_List(map));
			out.flush();
		}
		return null;
	}
}
